import smeRouter from "sme-router"

import login from "./views/login.ejs"
import index from "./views/index.ejs"
import adminList from "./views/adminList.ejs"
import advList from "./views/advList.ejs"

const router = new smeRouter("root", "html5")

window.router = router

router.route("/login", (req, res, next) => {
  res.render(login())
})
router.route("/index", (req, res, next) => {
  // req 是路径变化,页面要切换的时候的一些信息
  // res 提供了一些方法,可以在路径变化的时候,规定渲染什么,或重定向等
  next(
    index({
      subRoute: res.subRoute(),
      url: req.url,
    })
  )
})
router.route("/index/adminList", (req, res, next) => {
  res.render(adminList())
})
router.route("/index/advList", (req, res, next) => {
  res.render(advList())
})
router.route("*", (req, res, next) => {
  res.redirect("/index")
})
